/*
 * @(#)CollectionFrequency.java	1.0 08/01/07
 *
 * Copyright 2007 Fabio Gasparetti. All rights reserved.
 */

package org.tabularium.text.nlp;

import java.io.IOException;
import java.util.Iterator;
import org.tabularium.text.nlp.wordnet.PartOfSpeech;


/**
 * A simple interace for collecting word frequency by a given corpus.
 * <p>
 * Useful for DF-based similarity algorithms. 
 *  
 * @author Fabio Gasparetti
 * @version 1.0, 08/01/07
 */ 
public interface CollectionFrequency {
	public class TermFreq implements Comparable {
		String term;
		int pos;
		int freq;

		public TermFreq(String t, int pos, int f) {
			term = t;
			this.pos = pos;
			freq = f;
		}

		public int compareTo(Object o) {
			if (this == o) 
				return 0;
			TermFreq tf = (TermFreq) o;
			int c = term.compareTo(tf.term);
			if (c == 0) {
				c = pos - tf.pos;
			}
			return c;
		}
	}
	
	public abstract int getCollectionFrequency(String word);

	public abstract int getCollectionFrequency(String word, int pos);
	
	public abstract int getCollectionSize();
	
	public abstract int getNumberTerms();

	/**
	 * Returns an Iterator over the TermFreq collection.
	 */
	public abstract Iterator termFreqIterator();
	
	/**
	 * The first occurrence corresponds to the size of the collection.
	 */
	public abstract void load(String filename, CollectionFrequencyParser parser) throws IOException;

	//public double weight(short termFreqType, short collectionFreqType, short normalizationType)
	/**
	 * http://www.doc.ic.ac.uk/~jmag/classic/1988.Term-weighting%20approaches%20in%20automatic%20text%20retrieval.pdf
	 */
}
